<template>
	<view @click="open">
		<!-- 基础卡片(左边是图片,右边是文字) -->
		<view v-if="item.mode==='base'" class="cardlist">
			<view class="cardlist-image">
				<image :src="item.cover[0]" mode="aspectFill"></image>
			</view>
			<view class="cardlist-content">
				<view class="cardlist-content-title">
					<text>{{item.title}}</text>
					<like :types='types' :item='item'></like>
				</view>
				<view class="cardlist-content-desc">
					<view class="cardlist-content-desc-label">
						<view class="cardlist-content-desc-label-item">
							{{item.classify}}
						</view>
					</view>
					<view class="cardlist-content-desc-browse">
						{{item.browse_count}}浏览
					</view>
				</view>
			</view>
		</view>

		<!-- 多图模式卡片 -->
		<view v-if="item.mode==='column'" class="cardlist mode-column">
			<view class="cardlist-content">
				<view class="cardlist-content-title">
					<text>{{item.title}}</text>
					<like :types='types' :item='item'></like>
				</view>
				<view class="cardlist-image">
					<view class="cardlist-image-item" v-if="index<3" v-for="(item,index) in item.cover" :key="index">
						<image :src="item" mode="aspectFill"></image>
					</view>
				</view>
				<view class="cardlist-content-desc">
					<view class="cardlist-content-desc-label">
						<view class="cardlist-content-desc-label-item">
							{{item.classify}}
						</view>
					</view>
					<view class="cardlist-content-desc-browse">
						{{item.browse_count}}浏览
					</view>
				</view>
			</view>
		</view>

		<!-- 大图模式卡片 -->
		<view v-if="item.mode==='image'" class="cardlist mode-image">
			<view class="cardlist-image">
				<image :src="item.cover[0]" mode="aspectFill"></image>
			</view>
			<view class="cardlist-content">
				<view class="cardlist-content-title">
					<text>{{item.title}}</text>
					<like :types='types' :item='item'></like>
				</view>
				<view class="cardlist-content-desc">
					<view class="cardlist-content-desc-label">
						<view class="cardlist-content-desc-label-item">
							{{item.classify}}
						</view>
					</view>
					<view class="cardlist-content-desc-browse">
						{{item.browse_count}}浏览
					</view>
				</view>
			</view>
		</view>

	</view>
</template>

<script>
	export default {
		name: "card-list",
		props: {
			item: {
				type: Object,
				default () {
					return {}
				}
			},
			types:{
				type:String,
				default:''
			}
		},
		data() {
			return {
				
			};
		},
		methods:{
			open() {
				const item = this.item
				const params = {
					_id:item._id,
					author:item.author,
					title:item.title,
					create_time:item.create_time,
					thumbs_up_count:item.thumbs_up_count,
					browse_count:item.browse_count
				}
				this.$emit('open', item)
				uni.navigateTo({
					url:'/pages/home-detail/home-detail?params='+JSON.stringify(params)
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.cardlist {
		display: flex;
		padding: 10px;
		margin: 10px;
		border-radius: 5px;
		// 卡片阴影
		box-shadow: 0 0 5px 1px rgba($color: #000000, $alpha: 0.1);

		.cardlist-image {
			// 图片不被挤压
			flex-shrink: 0;
			width: 60px;
			height: 60px;
			border-radius: 5px;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.cardlist-content {
			display: flex;
			flex-direction: column;
			justify-content: space-between;
			padding-left: 10px;
			// 不指定宽度就是内容的宽度
			width: 100%;

			.cardlist-content-title {
				position: relative;
				font-size: 14px;
				color: #333333;
				font-weight: 400;
				padding-right: 30px;

				// 文字溢出隐藏
				text {
					overflow: hidden;
					text-overflow: ellipsis;
					display: -webkit-box;
					-webkit-line-clamp: 2;
					-webkit-box-orient: vertical;
				}

			}

			.cardlist-content-desc {
				display: flex;
				justify-content: space-between;
				font-size: 12px;

				.cardlist-content-desc-label {
					display: flex;

					.cardlist-content-desc-label-item {
						padding: 0 5px;
						border-radius: 15px;
						background-color: $mk-base-color;
						color: #FFFFFF;
					}
				}

				.cardlist-content-desc-browse {
					color: #999999;
				}
			}
		}

		// 同级多图模式样式
		&.mode-column {
			.cardlist-content {
				width: 100%;
				padding-left: 0;

				.cardlist-image {
					// 图片不被挤压
					flex-shrink: 0;
					display: flex;
					margin-top: 10px;
					width: 100%;
					height: 70px;
					margin-bottom: 10px;

					.cardlist-image-item {
						margin-left: 10px;
						width: 100%;
						border-radius: 5px;
						overflow: hidden;

						// 第一个元素不要左外填充
						&:first-child {
							margin-left: 0;
						}

						image {
							width: 100%;
							height: 100%;
						}
					}
				}

			}
		}

		// 同级大图模式样式
		&.mode-image {
			flex-direction: column;

			.cardlist-image {
				width: 100%;
				height: 100px;

				image {
					border-radius: 5px;
				}
			}

			.cardlist-content {
				padding-left: 0;
				margin-top: 10px;

				.cardlist-content-desc {
					display: flex;
					align-items: center;
					margin-top: 10px;
				}
			}
		}
	}
</style>
